package generatorModel

import (
	"CommonsProject/models/commonsModel"
	"CommonsProject/pkg/tools/sqlTool"
)

// Table  生成表
type Table struct {
	commonsModel.Model
	PackageName  string `from:"packageName" json:"packageName" gorm:"column:package_name;size:20;comment:包名"`
	FullPackage  string `from:"fullPackage" json:"fullPackage" gorm:"column:full_package;size:20;comment:全路径包名"`
	StructName   string `from:"structName" json:"structName" gorm:"column:struct_name;size:20;comment:结构体名称"`
	TabName      string `form:"tableName" json:"tableName" gorm:"column:table_name;unique;size:20;comment:表名称"`
	TableComment string `form:"tableComment" json:"tableComment" gorm:"column:table_comment;size:20;comment:表备注"`

	//路由相关内容
	IsMenu        bool   `from:"isMenu" json:"isMenu" gorm:"column:is_menu;size:1;comment:是否为菜单"`
	Title         string `from:"title" json:"title" gorm:"column:title;size:20;comment:菜单名称"`
	Icon          string `from:"icon" json:"icon" gorm:"column:icon;size:20;comment:菜单图标"`
	Url           string `from:"url" json:"url" gorm:"column:url;size:50;comment:url"`
	ParentId      uint   `from:"parenId" json:"parentId" gorm:"column:parent_id;size:10;comment:上级ID"`
	ComponentPath string `from:"componentPath" json:"componentPath" gorm:"column:component_path;size:150;comment:路由地址"`

	//一对多关系，当记录删除的时候，将从表也删除引用的记录
	Columns []*Column `json:"columns"`
}

func (t Table) TableName() string {
	return "generator_table"
}

func (t *Table) ToLower() {
	t.TabName = sqlTool.ToLowerField(t.StructName)
}
